package com.pi2e.view.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;
import butterknife.Bind;

import com.pi2e.R;
import com.pi2e.view.base.BaseActivity;
import com.pi2e.view.common.FootView;
import com.pi2e.view.common.HeaderView;

public class VipActivity extends BaseActivity implements OnClickListener,
		ViewFactory {

	private ImageSwitcher imageSwitcher;
	private Button button1, button2, btn_startRece;
	private int index = 0;// 用于浏览图片的次序
	private List<Drawable> list = new ArrayList<Drawable>();
	View mfootView;
	ImageView mImgPersons;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		imageSwitcher = (ImageSwitcher) this.findViewById(R.id.imageSwitcher1);
		button1 = (Button) this.findViewById(R.id.button1);
		button2 = (Button) this.findViewById(R.id.button2);
		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		mImgPersons.setOnClickListener(this);
		imageSwitcher.setFactory(this);
		// 往list集合里装载图片信息
		list.add(getResources().getDrawable(R.drawable.test_img01_vip));
		list.add(getResources().getDrawable(R.drawable.test_img02_vip));
		/*
		 * list.add(getResources().getDrawable(R.drawable.item4));
		 * list.add(getResources().getDrawable(R.drawable.item5));
		 * list.add(getResources().getDrawable(R.drawable.item6));
		 * list.add(getResources().getDrawable(R.drawable.item7));
		 * list.add(getResources().getDrawable(R.drawable.item8));
		 */
		// 初始化加载图片的信息
		if (list.size() > 0) {
			imageSwitcher.setImageDrawable(list.get(0));
		}
	}

	@Override
	public HeaderView initHeaderView() {
		return null;
	}

	@Override
	public void setContentView() {
		setContentView(R.layout.activity_vip);

	}

	@Override
	public void initView() {
		mfootView = findViewById(R.id.footId);
		mImgPersons = (ImageView) findViewById(R.id.img_persons);
		btn_startRece = (Button) findViewById(R.id.btn_startRece);
		btn_startRece.setOnClickListener(this);
	}

	@Override
	public void initFootView() {
		FootView footView = new FootView(VipActivity.this, mfootView);
		footView.getBtn_ok().setText("返 回");
		footView.getBtn_ok().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				finish();
			}
		});
	}

	@Override
	public void onClick(View v) {
		Intent it = null;
		switch (v.getId()) {
		case R.id.button1:
			index--;
			if (index < 0) {
				index = list.size() - 1;
			}
			imageSwitcher.setImageDrawable(list.get(index));
			break;
		case R.id.button2:
			index++;
			if (index >= list.size()) {
				index = 0;
			}
			imageSwitcher.setImageDrawable(list.get(index));
			break ;
		case R.id.img_persons:
			it = new Intent(VipActivity.this, TodayVipActivity.class);

			break ;
		case R.id.btn_startRece:
			it = new Intent(VipActivity.this, GuideVipActivity.class);

			break;
		default:
			break;
		}
		if (null != it) {
			startActivity(it);
		}

	}

	@Override
	public View makeView() {
		// TODO Auto-generated method stub
		return new ImageView(VipActivity.this);
	}

}
